package com.peng.leetcode.palindrome;

import java.util.ArrayList;
import java.util.List;

/**
 * PalindromeString
 *
 * 125. 验证回文串
 *
 * @author: lupeng6
 * @create: 2021/4/7 10:38
 */
public class PalindromeString {

    public static void main(String[] args) {
        String str = "A man, a plan, a canal: Panama";
        System.out.println(new PalindromeString().isPalindrome(str));
    }


    public boolean isPalindrome(String s) {
        List<Character> list = new ArrayList<>(s.length());

        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (Character.isLetterOrDigit(c)) {
                list.add(Character.toLowerCase(c));
            }
        }

        int l = 0;
        int r = list.size() - 1;

        while (l < r) {
            if (list.get(l) != list.get(r)) {
                return false;
            }
            l++;
            r--;
        }
        return true;
    }


}
